package org.xutils.view.log;

/**
 * Created by ZZH on 4/19/21.
 *
 * @Date: 4/19/21
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description:
 */
public class Log {
    private boolean isDebug = false;

    public interface AndroidLogFactory {

        void d(String msg);

        void d(Throwable msg);

        void e(String msg);

        void e(Throwable msg);

        void i(String msg);

        void w(String msg);

        void w(Throwable msg);

        void a(String msg);
    }

    private Log() {
        //no instance
    }

    private static Log mLog;

    public static Log getInstance() {
        if (mLog == null) {
            synchronized (Log.class) {
                if (mLog == null) {
                    mLog = new Log();
                }

            }
        }
        return mLog;
    }

    public void setDebug(boolean debug) {
        isDebug = debug;
    }

    public boolean isDebug() {
        return isDebug;
    }

    private AndroidLogFactory mAndroidLogFactory;

    public void init(AndroidLogFactory androidLogFactory) {
        mAndroidLogFactory = androidLogFactory;
    }

    public final void d(String msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.d(msg);
        }
    }

    public final void d(Throwable msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.d(msg);
        }
    }

    public final void e(String msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.e(msg);
        }
    }

    public final void e(Throwable msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.e(msg);
        }
    }

    public final void w(String msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.w(msg);
        }
    }

    public final void w(Throwable msg) {
        if (mAndroidLogFactory != null && isDebug()) {
            mAndroidLogFactory.w(msg);
        }
    }

}
